package mrusanov.battle

import util.Random
import mrusanov.terrain.TerrainType

class PlayersDuelAttack(val attacker:PlayerState, val defender:PlayerState, val arena:MiniArena, random:Random = new Random) {

  def executeAttack():AttackInfo = {
    if (attackIsSuccessful()) {
      attacker.performAttack(defender)
      new AttackInfo(attacker, defender, true, arena)
    } else {
      new AttackInfo(attacker, defender, false, arena)
    }

  }

  private def attackIsSuccessful():Boolean = {
    val defence = defender.playerType.defence(arena.terrain)
    random.nextInt(101) > defence
  }
}
